<html>
<head><meta charset="utf-8"><title>evaluate require_consts before const prop · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html">evaluate require_consts before const prop</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239674049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674049">(May 20 2021 at 23:19)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> you told me to move evaluation of required_consts before const prop</p>



<a name="239674116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674116">(May 20 2021 at 23:20)</a>:</h4>
<p>we've talked about doing so right before <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L151">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L151</a></p>



<a name="239674159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674159">(May 20 2021 at 23:20)</a>:</h4>
<p>right before that there's a call to <code>ConstPropagator::new</code></p>



<a name="239674233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674233">(May 20 2021 at 23:21)</a>:</h4>
<p>inside <code>ConstPropagator::new</code> we do <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L397-L402">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L397-L402</a></p>



<a name="239674290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674290">(May 20 2021 at 23:22)</a>:</h4>
<p>which does <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L691-L702">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L691-L702</a></p>



<a name="239674310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674310">(May 20 2021 at 23:22)</a>:</h4>
<p>so we are already evaluating things</p>



<a name="239674367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674367">(May 20 2021 at 23:23)</a>:</h4>
<p>so ... does that mean that we should already be able to just remove <code>Span</code> from <code>Constant</code> and shouldn't have any issue or am I missing something?</p>



<a name="239674462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674462">(May 20 2021 at 23:25)</a>:</h4>
<p>well ... I think the problem is that we are throwing away the result of the evaluation <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L701">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L701</a>, right?</p>



<a name="239674573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239674573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239674573">(May 20 2021 at 23:26)</a>:</h4>
<p>I guess we should place that back into MIR's body?</p>



<a name="239679675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239679675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239679675">(May 21 2021 at 00:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116266">Santiago Pastorino</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239674233">said</a>:</p>
<blockquote>
<p>inside <code>ConstPropagator::new</code> we do <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L397-L402">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L397-L402</a></p>
</blockquote>
<p>that pushes a dummy body</p>



<a name="239679687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239679687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239679687">(May 21 2021 at 00:30)</a>:</h4>
<p>not the one being optimized</p>



<a name="239679699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239679699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239679699">(May 21 2021 at 00:31)</a>:</h4>
<p>and the dummy has no required_consts</p>



<a name="239679727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239679727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239679727">(May 21 2021 at 00:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116266">Santiago Pastorino</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239674462">said</a>:</p>
<blockquote>
<p>well ... I think the problem is that we are throwing away the result of the evaluation <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L701">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L701</a>, right?</p>
</blockquote>
<p>the const evaluator is the wrong place. it cannot modify MIR</p>



<a name="239679731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239679731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239679731">(May 21 2021 at 00:31)</a>:</h4>
<p>it only has read access</p>



<a name="239771520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239771520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239771520">(May 21 2021 at 15:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239679699">said</a>:</p>
<blockquote>
<p>and the dummy has no required_consts</p>
</blockquote>
<p>ok, I'm not sure what's the purpose of this but I guess I'd need to do something similar to what <code>push_stack_frame</code> does but for the optimized body</p>



<a name="239771884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239771884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239771884">(May 21 2021 at 15:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239679727">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116266">Santiago Pastorino</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239674462">said</a>:</p>
<blockquote>
<p>well ... I think the problem is that we are throwing away the result of the evaluation <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L701">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/interpret/eval_context.rs#L701</a>, right?</p>
</blockquote>
<p>the const evaluator is the wrong place. it cannot modify MIR</p>
</blockquote>
<p>got it so will do right before <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L151">https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_mir/src/transform/const_prop.rs#L151</a> as you've said</p>



<a name="239867895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239867895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239867895">(May 22 2021 at 11:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116266">Santiago Pastorino</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239674049">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="124288">oli</span> you told me to move evaluation of required_consts before const prop</p>
</blockquote>
<p>could you give some context? what do you mean by this, and why do you want to do this?</p>



<a name="239867902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239867902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239867902">(May 22 2021 at 11:56)</a>:</h4>
<p>note that this is not possible in general since evaluating the const might require monomorphization</p>



<a name="239867907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239867907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239867907">(May 22 2021 at 11:56)</a>:</h4>
<p>so there can't be any "moving" this earlier</p>



<a name="239867927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239867927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239867927">(May 22 2021 at 11:57)</a>:</h4>
<p>but what we could do (and what it sounds like you want to do) is to eagerly evaluate the consts that we can pre-monomorphization and put their result into the MIR.</p>



<a name="239868189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239868189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239868189">(May 22 2021 at 12:01)</a>:</h4>
<p>That's what we're trying to do here. This will cover a lot of cases already and then we can remove the spans from mir::Constant as we don't need the precise spans anymore. The spans and errors are handled on required consts from then on, allowing you to know that any evaluation will succeed and thus we can ICE if it doesn't</p>



<a name="239868254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239868254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239868254">(May 22 2021 at 12:02)</a>:</h4>
<p>CTFE will still have to do some fancy dancing with promoteds, as these can't all be pre evaluated, but we can still pick up the span from the required const list instead of having a bad span at the operand level</p>



<a name="239868399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239868399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239868399">(May 22 2021 at 12:04)</a>:</h4>
<blockquote>
<p>allowing you to know that any evaluation will succeed</p>
</blockquote>
<p>you have no way to know that</p>



<a name="239868411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239868411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239868411">(May 22 2021 at 12:04)</a>:</h4>
<p>since you can only evaluate some of the required_consts early (pre-monomorph)</p>



<a name="239868426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239868426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239868426">(May 22 2021 at 12:05)</a>:</h4>
<p>those that you cannot (because they depend on generic params, e.g. associated consts), you have to still fully support to fail later along the chain (i.e., during monomorphization)</p>



<a name="239868503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239868503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239868503">(May 22 2021 at 12:06)</a>:</h4>
<p>(and yes, on top of that promoteds in const/static bodies -- and only there -- can fail to evaluate)</p>



<a name="239873329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873329">(May 22 2021 at 13:35)</a>:</h4>
<blockquote>
<p>since you can only evaluate some of the required_consts early (pre-monomorph)</p>
</blockquote>
<p>By fail, I mean to have an actual error, not simply be <code>TooGeneric</code></p>



<a name="239873397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873397">(May 22 2021 at 13:36)</a>:</h4>
<p>All of this work here is just about precise spans. We're not changing any behaviour wrt what compiles and what not</p>



<a name="239873434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873434">(May 22 2021 at 13:37)</a>:</h4>
<p>But during codegen, we know for a fact that no evaluation of constants in operands can fail, as all required const already got evaluated successfully</p>



<a name="239873443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873443">(May 22 2021 at 13:37)</a>:</h4>
<p>So we do not need good spans in operands</p>



<a name="239873498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873498">(May 22 2021 at 13:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239873434">said</a>:</p>
<blockquote>
<p>But during codegen, we know for a fact that no evaluation of constants in operands can fail, as all required const already got evaluated successfully</p>
</blockquote>
<p>define "during codegen". we don't know it in <a href="https://github.com/rust-lang/rust/blob/9a3214e9be41a5d50ae6ba9bb8422dcc2cb10473/compiler/rustc_codegen_ssa/src/mir/mod.rs#L192">this loop</a>. we only know it <em>after</em> that loop. but I don't see how that helps wrt preserving spans.</p>



<a name="239873548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873548">(May 22 2021 at 13:40)</a>:</h4>
<blockquote>
<p>The spans and errors are handled on required consts from then on</p>
</blockquote>
<p>I am trying to read between your words here, are you saying <code>required_consts</code> becomes something like <code>Vec&lt;(Const, Span)&gt;</code>?<br>
(it'd help if the complete proposal was explained in slightly more concrete terms.^^)</p>



<a name="239873620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873620">(May 22 2021 at 13:40)</a>:</h4>
<p>Yes that's what it becomes and is already in <span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> 's PR</p>



<a name="239873653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873653">(May 22 2021 at 13:41)</a>:</h4>
<p>okay. so in that loop you are fine then.</p>



<a name="239873656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873656">(May 22 2021 at 13:41)</a>:</h4>
<p>Sorry about the confusion, this is all spread discussion across 3 places</p>



<a name="239873667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239873667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239873667">(May 22 2021 at 13:41)</a>:</h4>
<p>which I guess finally gets us back to the question you raised earlier -- what about promoteds in const/static bodies? those are not required and they can fail.</p>



<a name="239874052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239874052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239874052">(May 22 2021 at 13:48)</a>:</h4>
<p>We can walk the required const list and search it for the right span</p>



<a name="239880227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239880227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239880227">(May 22 2021 at 15:21)</a>:</h4>
<p>promoteds are not in that list though</p>



<a name="239880266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239880266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239880266">(May 22 2021 at 15:22)</a>:</h4>
<p>(and they shouldnt be, they are not required)</p>



<a name="239880269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239880269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239880269">(May 22 2021 at 15:22)</a>:</h4>
<p>that's the entire problem^^</p>



<a name="239880330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239880330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239880330">(May 22 2021 at 15:23)</a>:</h4>
<p>Ah right</p>



<a name="239880470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239880470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239880470">(May 22 2021 at 15:25)</a>:</h4>
<p>Ah, but promoteds are not a problem, as we already report anything directly where it happens inside the promoted's body</p>



<a name="239880531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239880531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239880531">(May 22 2021 at 15:26)</a>:</h4>
<p>All we care about is named constants I guess</p>



<a name="239884568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239884568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239884568">(May 22 2021 at 16:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239880470">said</a>:</p>
<blockquote>
<p>Ah, but promoteds are not a problem, as we already report anything directly where it happens inside the promoted's body</p>
</blockquote>
<p>ah and those spans are actually inside the relevant constant... yeah that should work</p>



<a name="239884613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239884613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239884613">(May 22 2021 at 16:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/evaluate.20require_consts.20before.20const.20prop/near/239873620">said</a>:</p>
<blockquote>
<p>Yes that's what it becomes and is already in <span class="user-mention silent" data-user-id="116266">Santiago Pastorino</span> 's PR</p>
</blockquote>
<p>do you have a link to that PR?</p>



<a name="239889886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/evaluate%20require_consts%20before%20const%20prop/near/239889886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/evaluate.20require_consts.20before.20const.20prop.html#239889886">(May 22 2021 at 18:07)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/85208">https://github.com/rust-lang/rust/pull/85208</a> but maybe I saw commits on other branches instead of on that PR</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>